mui.init({
	beforeback: function(){
		return true;
	}
});
mui.plusReady(function() {
	
	var btn_reset = CmwMcore.$("btn_reset");
	MeventMgr.onTouchstart(btn_reset,function(event,self){
		if(!valid()) return;
		submitForm();
	});
	
	
	
	function valid(){
		var pwd1 = $("#pwd1").val();
		var pwd2 = $("#pwd2").val();
		var pwd_pattern = /^(?=[0-9a-zA-Z]+\d)(?=[0-9a-zA-Z]+[a-zA-Z])(?=[0-9a-zA-Z]).{8,16}$/;
		if(!pwd1){
			mui.alert("请输入新密码!");
			return false;
		}
		if(!pwd2){
			mui.alert("重复密码不能为空!");
			return false;
		}
		if(pwd1!=pwd2){
			mui.alert("两次密码不一致!");
			return false;
		}
		if(!pwd_pattern.test(pwd1) || (pwd1.length < 8  || pwd1.length > 16)){
			mui.alert("密码：请输入8-16位字母加数字的组合,例如：Abc123456");
			$("#pwd1").val("");
			$("#pwd2").val("");
			return false;
		}
				
		return true;
	}
	
	
	function submitForm(){
		var newpassword = $("#pwd2").val();
		var url=UrlConfig.updatepassword;
		var pars = {newpassword:newpassword};
		MuiEventMgr.ajax(url,{pars:pars,
		  	sfn : function(data){
		  		var status = data.status;
		  		if(status=="true"){
					mui.alert("修改成功!");
					var win = plus.webview.getWebviewById(appid);
					win.show();
					win.evalJS("openTab(null,subpages2[0]);");
				}else if(status=="error"){
					mui.alert("登陆密码不能与交易密码相同!");
				}else{
					mui.alert("修改失败!");
				}	        		
		  	},ffn : function(){
		  		mui.alert("获取数据失败：["+err+"]");
		  	}
		});
	}
});

	
